package cn.innosmart.aq.camera;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import cn.innosmart.aq.R;

/**
 * 输入Wifi密码的对话框
 * Created by David on 2015/8/4.
 */
public class WifiPasswordDialog extends Dialog {
    private Context mContext;

    public WifiPasswordDialog(Context context) {
        super(context, R.style.dialog);
        init(context);
    }

    public WifiPasswordDialog(Context context, int theme) {
        super(context, theme);
        init(context);
    }

    public WifiPasswordDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    private Button bt_positive;
    private Button bt_negative;
    private TextView tv_title;
    private void init(Context context) {
        this.mContext = context;
        View contentView = View.inflate(getContext(), R.layout.dialog_input_wifi_password, null);
        setContentView(contentView);
        bt_positive = (Button) findViewById(R.id.bt_positive);
        bt_negative = (Button) findViewById(R.id.bt_negative);
        bt_negative.setOnClickListener(mBtnOnClickListener);
        bt_positive.setOnClickListener(mBtnOnClickListener);
        tv_title = (TextView) findViewById(R.id.tv_title);
        //getWindow().setWindowAnimations(R.anim.alpha_in);
        /**
         * 强制设置点击外部不取消对话框
         */
        setCanceledOnTouchOutside(false);
    }

    public void setTitle(CharSequence title) {
        tv_title.setText(title);
    }

    public void setTitle(int titleId) {
        tv_title.setText(mContext.getText(titleId));
    }


    private View.OnClickListener mBtnOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.bt_positive:
                    mPositiveButtonListener.onClick(v);
                    break;
                case R.id.bt_negative:
                    mNegativeButtonListener.onClick(v);
                    break;
            }
        }
    };

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    @Override
    public void setCanceledOnTouchOutside(boolean cancel) {
        super.setCanceledOnTouchOutside(cancel);
    }

    private CharSequence mPositiveButtonText;
    private View.OnClickListener mPositiveButtonListener;
    private CharSequence mNegativeButtonText;
    private View.OnClickListener mNegativeButtonListener;

    public void setPositiveButton(int textId, View.OnClickListener listener) {
        mPositiveButtonText = mContext.getText(textId);
        bt_positive.setVisibility(View.VISIBLE);
        bt_positive.setText(mPositiveButtonText);
        mPositiveButtonListener = listener;
    }

    public void setPositiveButton(CharSequence text, View.OnClickListener listener) {
        mPositiveButtonText = text;
        bt_positive.setVisibility(View.VISIBLE);
        bt_positive.setText(mPositiveButtonText);
        mPositiveButtonListener = listener;
    }

    public void setNegativeButton(int textId, View.OnClickListener listener) {
        mNegativeButtonText = mContext.getText(textId);
        bt_negative.setVisibility(View.VISIBLE);
        bt_negative.setText(mNegativeButtonText);
        mNegativeButtonListener = listener;
    }

    public void setNegativeButton(CharSequence text, View.OnClickListener listener) {
        mNegativeButtonText = text;
        bt_negative.setVisibility(View.VISIBLE);
        bt_negative.setText(mNegativeButtonText);
        mNegativeButtonListener = listener;
    }

    @Override
    public void show() {
        super.show();
    }


}
